﻿using SharePhone.Common;
using SharePhone.Provider;

namespace SharePhone.Search
{
    public class SPSearch
    {
        private readonly string WebUrl;
        private SearchMetaData smd;

        public SPSearch(string webUrl)
        {
            WebUrl = webUrl;
        }

        public CredentialSettings Credentials { get; set; }

        public void Search(QueryPacket query, SearchComplete callback)
        {
            SearchProvider.Search(query.ToString(), WebUrl, callback, Credentials);
        }

        public void KeywordSearch(string text, SearchComplete callback)
        {
            var query = new QueryPacket();
            query.Query = text;
            query.QueryType = QueryType.STRING;
            query.EnableStemming = true;
            query.ImplicitAndBehavior = true;
            Search(query, callback);
        }

        public void GetSearchMetaData(SearchMetadataComplete callback)
        {
            SearchProvider.GetSearchMetaData(WebUrl, callback, Credentials);
        }
    }
}